import {useState, useCallback, useEffect} from "react";
export function useWidth(defaultWidth){
    var [width, setWidth] = useState(defaultWidth);

    var onChange = useCallback(()=>{
        setWidth(document.body.clientWidth);
    },[]);

    useEffect(()=>{
        window.addEventListener("resize", onChange, false);
        return ()=>{
            window.removeEventListener("resize", onChange, false)
        }
    },[onChange]);
    
    return width;
}